package gijoe.service;



import gijoe.dao.UserDao;
import gijoe.dto.AbroadDto;
import gijoe.dto.ApplicationDto;
import gijoe.dto.AwdDto;
import gijoe.dto.BoardNoticeDto;
import gijoe.dto.BoardRecruitDto;
import gijoe.dto.CareerDto;
import gijoe.dto.CertiDto;
import gijoe.dto.ClubDto;
import gijoe.dto.CommcdDto;
import gijoe.dto.HopeDto;
import gijoe.dto.InfoDto;
import gijoe.dto.IntroDto;
import gijoe.dto.LangDto;
import gijoe.dto.ParttimeDto;
import gijoe.dto.SubmitDto;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImple implements UserService {

	@Autowired
	private SqlSession sqlSession;
	
	
	/*----------------------------------------------------------------공지사항 START*/
	// 공지사항 리스트
	@Override
	public List<BoardNoticeDto> noticeSelectAll() {
		UserDao boardnotice = sqlSession.getMapper(UserDao.class);
		List<BoardNoticeDto> list = boardnotice.noticeSelectAll();
		return list;
	}

	// 공지사항 리스트 하나만 select
	@Override
	public BoardNoticeDto noticeSelectOne(String notice_num) {
		UserDao boardnotice = sqlSession.getMapper(UserDao.class);
		BoardNoticeDto dto = boardnotice.noticeSelectOne(notice_num);
		return dto;
	}
	/*----------------------------------------------------------------공지사항 END*/
	
	//--------------------------채용공고------------------
	@Override
	public List<BoardRecruitDto> recruitSelectAll() {
		UserDao boardrecruit = sqlSession.getMapper(UserDao.class);
		List<BoardRecruitDto> recruit_list = boardrecruit.recruitSelectAll();
		return recruit_list;
	}
	@Override
	public List<BoardRecruitDto> recruitSelectAll(BoardRecruitDto dto) {
		UserDao boardrecruit = sqlSession.getMapper(UserDao.class);
		List<BoardRecruitDto> recruit_list = boardrecruit.recruitSelectAll(dto);
		return recruit_list;
	}
	@Override
	public BoardRecruitDto recruitSelectOne(String rcrt_num) {
		UserDao boardrecruit = sqlSession.getMapper(UserDao.class);
		BoardRecruitDto dto = boardrecruit.recruitSelectOne(rcrt_num);
		return dto;
	}

	@Override
	public void recruitDelete(String rcrt_num,String app_nm, String email, String app_pwd) {
		UserDao dao = sqlSession.getMapper(UserDao.class);
		dao.recruitDelete(rcrt_num,app_nm, email, app_pwd);
	}
	
	@Override
	public List<BoardRecruitDto> recruitList() {
		UserDao dao = sqlSession.getMapper(UserDao.class);
		List<BoardRecruitDto> list= dao.recruitList();
		return list;
	}

	
	  //지원서------------------------------------------------------
	@Override
	public int applicainsert(ApplicationDto dto) {
		UserDao appinsert = sqlSession.getMapper(UserDao.class);
		return appinsert.AppLicaTioninsert(dto);
			
	}

	@Override
	public List<ApplicationDto> app_receiptSelectAll() {
		UserDao appselectAll = sqlSession.getMapper(UserDao.class);
		List<ApplicationDto> list=appselectAll.app_receiptSelectAll();
		return list;
	}

	//합격자발표(경력,신입 => 코드 선택)
		@Override
		public List<CommcdDto> userRecruitCdSelect() {
			UserDao recruitCdSelectAll = sqlSession.getMapper(UserDao.class);
			List<CommcdDto> cd_list = recruitCdSelectAll.userRecruitCdSelect();
			return cd_list;
		}
		
		@Override
		public List<BoardRecruitDto> userRecruitSelectAll() {
			UserDao recruitSelectAll = sqlSession.getMapper(UserDao.class);
			List<BoardRecruitDto> recruit_list = recruitSelectAll.userRecruitSelectAll();
			return recruit_list;
		}

		@Override
		public Map<String, Object> userPassForm() {
			
			UserDao user_pass_form = sqlSession.getMapper(UserDao.class);
			
			List<BoardRecruitDto> recruit_list = user_pass_form.userRecruitSelectAll();
			List<CommcdDto> cd_list = user_pass_form.userRecruitCdSelect();
			
			Map<String, Object> pass =  new HashMap<String, Object>();
			
			pass.put("cd_list", cd_list);
			pass.put("recruit_list", recruit_list);
			
			return pass;
		}

		@Override
		public ApplicationDto userPassSearch(String rcrt_num, String recruit_cd, String app_nm, 
											 String birth_yy, String birth_mm,String birth_dd, 
											 String email_id, String email_addr, String app_pwd) {
			
			String birth = (birth_yy + birth_mm + birth_dd);
			String email = (email_id +"@"+ email_addr);
		
			ApplicationDto dto=new ApplicationDto();
			
			dto.setRcrt_num(rcrt_num);
			dto.setRecruit_cd(recruit_cd);
			dto.setApp_nm(app_nm);
			dto.setBirth(birth);
			dto.setEmail(email);
			dto.setApp_pwd(app_pwd);
			System.out.println(dto.toString());
			UserDao user_pass_search = sqlSession.getMapper(UserDao.class);		
					
			ApplicationDto applicationdto = user_pass_search.userPassSearch(dto);
			
			
			return applicationdto;
		}

	//------------------------------------------------------------------------
		//지원서 접수 시작 
		//기본사항페이지 info insert
		@Override
		public int Infoinsert(InfoDto dto) {
			UserDao infoinsert = sqlSession.getMapper(UserDao.class);
			return infoinsert.Infoinsert(dto);
		}
		//기본사항 페이지 대학교 insert
		@Override
		public int Schinsert(String app_num,String sch_cd,
				String sch_fr_ymm,String sch_to_ymm, String sch_ent_cd,String sch_nm,String sch_mjr_cd,
				String sch_mjr_nm,String sch_gra_cd,String sch_mark,String sch_fl_mark,String sch_grad_yn) {
			UserDao schinsert = sqlSession.getMapper(UserDao.class);
			return schinsert.Schinsert( app_num, sch_cd,
					 sch_fr_ymm, sch_to_ymm,  sch_ent_cd, sch_nm, sch_mjr_cd,
					 sch_mjr_nm, sch_gra_cd, sch_mark, sch_fl_mark, sch_grad_yn);
		}

		//경력사항 해외연서 인서트
		@Override
		public int AbroadInsert(AbroadDto dto) {
			System.out.println(dto.toString());
			UserDao abroadinsert = sqlSession.getMapper(UserDao.class);
			return abroadinsert.AbroadInsert(dto);
		}
		//경력사항 경력부분 인서트
		@Override
		public int Careerinser(CareerDto dto) {
			System.out.println(dto.toString());
			UserDao careerinser = sqlSession.getMapper(UserDao.class);
			return careerinser.CareerInser(dto);
		}
		//경력사항 아르바이경력 인서트
		@Override
		public int Parttimeinsert(ParttimeDto dto) {
			System.out.println(dto.toString());
			UserDao parttimeinsert = sqlSession.getMapper(UserDao.class);
			return parttimeinsert.Parttimeinsert(dto);
		}
		//경력사항 동아리 사항 인서트
		@Override
		public int Clubinsert(ClubDto dto) {
			System.out.println(dto.toString());
			UserDao clubinsert = sqlSession.getMapper(UserDao.class);
			return clubinsert.Clubinsert(dto);
		}

		//기타사항 수상경력 insert
		@Override
		public int Awdinsert(AwdDto dto) {
			UserDao awdinsert = sqlSession.getMapper(UserDao.class);
			return awdinsert.Awdinsert(dto);
		}
		//기타사항 외국어 insert
		@Override
		public int Langinsert(LangDto dto) {
			UserDao langinsert = sqlSession.getMapper(UserDao.class);
			return langinsert.Langinsert(dto);
		}
		//해외희망근무 insert
		@Override
		public int Hopeinsert(HopeDto dto) {
			UserDao hopeinsert = sqlSession.getMapper(UserDao.class);
			return hopeinsert.Hopeinsert(dto);
		}
		//기타사항 자격면허 insert
		@Override
		public int Certiinsert(CertiDto dto) {
			UserDao certiinsert = sqlSession.getMapper(UserDao.class);
			return certiinsert.Certiinsert(dto);
		}

		//자기소개페이지에 자기소개제목뿌리기
		@Override
		public ApplicationDto SelfSelect(String app_num) {
			UserDao selfSelect = sqlSession.getMapper(UserDao.class);
			ApplicationDto dto = selfSelect.SelfSelect(app_num);
			return dto;
		}
		//자기소개페이지 insert
		@Override
		public int Introinsert(IntroDto dto) {
			UserDao introinsert = sqlSession.getMapper(UserDao.class);
			return introinsert.Introinsert(dto);
		}

		//최종제출 페이지 공고명받아오기
		@Override
		public ApplicationDto Apprecruit_nm(String app_num) {
			UserDao apprecruit_nm = sqlSession.getMapper(UserDao.class);
			ApplicationDto dto=apprecruit_nm.Apprecruit_nm(app_num);
			return dto;
		}
		//최종제출 insert
		@Override
		public int Submitinster(SubmitDto dto) {
			UserDao submitinster = sqlSession.getMapper(UserDao.class);
			return submitinster.Submitinster(dto);
		}
		//지원자 지원상태 업데이트
		@Override
		public int Submitupdate(SubmitDto dto) {
			UserDao submitupdate = sqlSession.getMapper(UserDao.class);
			return submitupdate.Submitupdate(dto);
		}

	//지원페이지 지원확인
    @Override
    public ApplicationDto Appidentify(ApplicationDto dto) {
      UserDao appidentify = sqlSession.getMapper(UserDao.class);
      ApplicationDto adto=  appidentify.Appidentify(dto);
      return adto;
    }
    //지원페이지 이메일 확인
    @Override
    public ApplicationDto Emailoverlap(String email, String rcrt_num) {
      UserDao emailoverlap = sqlSession.getMapper(UserDao.class);
      ApplicationDto adto=  emailoverlap.Emailoverlap(email, rcrt_num);
      return adto;
    }
		


}
